package ru.tulupov.guessgame;

import java.util.Random;

/**
 * Guess game main logic
 * @author <a href="mailto:zhekka3@gmail.com">Eugene Tulupov</a>
 */
public class Game {
	public static final int MAX_ATTEMPT_COUNT = 8;
	public static final int MIN_VALUE = 0;
	public static final int MAX_VALUE = 100;
	private int randomNumber;
	private int attempt;

	enum Result {
		LESS, EQUAL, MORE
	};

	public Game() {
		this.randomNumber = MIN_VALUE
				+ new Random().nextInt(MAX_VALUE - MIN_VALUE + 1);
	}
	
	public int getRandomNumber() {
		return randomNumber;
	}

	/**
	 * 
	 * @return
	 * @throws GameOverException
	 */
	public Result guess(int number) {
		Result result = null;

		if (attempt >= MAX_ATTEMPT_COUNT) {
			throw new GameOverException();
		}
		
		attempt++;
		
		if (number < randomNumber) {
			result = Result.LESS;
		} else if (number == randomNumber) {
			result = Result.EQUAL;
		} else if (number > randomNumber) {
			result = Result.MORE;
		}

		return result;
	}
}
